package net.huashitong.Indicators.api;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import net.huashitong.Indicators.entity.*;
import net.huashitong.Indicators.service.*;
import net.huashitong.until.Until;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

@Controller
@RequestMapping("/data")
public class GetDataCtrl extends JsonBaseController {

    @Autowired
    private OneIndexService oneService;
    @Autowired
    private TwoIndexService twoService;
    @Autowired
    private ThreeIndexService threeService;
    @Autowired
    private AreaCodeService areaService;
    @Autowired
    private ChildViewService secondService;
    @Autowired
    private GetDataService getDataService;
    @Autowired
    private IndexDataService indexDataService;
    @Override
    protected String getView(String s) {
        return null;
    }


    @ResponseBody
    @RequestMapping("/getdata")
    public Message getData() {
        JSONObject jsonObject = null;
        JSONArray jsonArray1 = null;
        String sb = "";
      /*  try {
            //HttpClient client = new DefaultHttpClient();//过时了 强哥不想用、换一个。
            HttpClient client = HttpClientBuilder.create().build();
            HttpGet httpget = new HttpGet(Until.UPDATE_URL);
            RequestConfig reqConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
            httpget.setConfig(reqConfig);
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            String response  = client.execute(httpget,responseHandler);
             jsonObject =JSONObject.parseObject(response);
             jsonArray1=jsonObject.getJSONArray("returndata");
             String code=null;
             String cname=null;
             for(int  i =0;i<=jsonArray1.size();i++)
             {
                 JSONObject object  = (JSONObject)jsonArray1.get(i);
                  code = object.getString("code");
                  cname = object.getString("cname");
             }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }*/
        return coverMessage("200", "successful");
    }

    @ResponseBody
    @RequestMapping("/getYueDuIndicator")
    public Message getIndicatorName() {
        //厦门市月度数据 ，Y
        // Map<String,Object> listmap = getDataService.getYueDuDataFromURL(Until.XMDB_YUEDU,"Y");
        // getDataService.saveIndexs(listmap,"Y");
        // getDataService.saveYueDuData(Until.XMDB_YUEDU,"Y","D");
        List<IndexData> list = indexDataService.getNodataCode();
        return coverMessage("200", "successful", list);
    }

    @ResponseBody
    @RequestMapping("/getJiDuIndicator")
    public Message getJiDuIndicator() {
        // Map<String,Object> listmap = getDataService.getYueDuDataFromURL(Until.XMDB_JIDU,"J");
        // getDataService.saveIndexs(listmap,"J");
        /*getDataService.saveYueDuData(Until.XMDB_JIDU, "J", "D");*/
        return coverMessage("200", "successful");
    }


    /**
     * 保存指标模板(月度)
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/getIndicatorMouldYueDu")
    public Message getIndicatorMouldYueDu() {
        /**
         * String JIDU_9DI = "app9sjd";// 	9个设区市季度数据（APP）
         * String NIANDU_9DI = "app9snd";//  9个设区市年度数据（APP）
         * String YUEDU_9DI = "app9syd";//  9个设区市月度数据（APP）
         * String JIDU_FUSHENGJI15 = "appfsjjd";//   十五个副省级季度数据（APP）
         * String NIANDU_FUSHENGJI15 = "appfsjnd";//   十五个副省级年度数据（APP）
         * String YUEDU_FUSHENGJI15 = "appfsjyd";//   十五个副省级月度数据（APP）
         * String JIDU_TEQU4 = "appjjtqjd";//    四个经济特区季度数据（APP）
         * String NIANDU_TEQU4 = "appjjtqnd";//    四个经济特区年度数据（APP）
         * String YUEDU_TEQU4 = "appjjtqyd";//    四个经济特区月度数据（APP）
         * String JIDU_QUANGUO = "appqgjd";//  全国季度数据（APP）
         * String NIANDU_QUANGUO = "appqgnd";//  全国年度数据（APP）
         * String YUEDU_QUANGUO = "appqgyd";//  全国月度数据（APP）
         * String JIDU_QUJI = "appqjjd";//  区级季度数据（APP）
         * String NIANDU_QUJI = "appqjnd";//  区级年度数据（APP）
         * String YUEDU_QUJI = "appqjyd";//  区级月度数据（APP）
         * String YEUDU_SHOUYE = "appshouye";//    首页月度数据（APP）
         * String JIDU_SHIJI = "appsjjd";//  市级季度数据（APP）
         * String NIANDU_SHIJI = "appsjnd";//  市级年度数据（APP）
         * String YUEDU_SHIJI = "appsjyd";//  市级月度数据（APP）
         */
        // A 区级 B 四个特区，C 十五个副省级 D 市级数据，E 九地市  G 全国  P 全省
        //市级月度指标
//        Map<String, Object> listmap1 = getDataService.getYueDuDataFromURL(Until.YUEDU_SHIJI, "Y", "D");
//        getDataService.saveIndexs(listmap1, "Y", "D");
        //区级月度指标
//        Map<String, Object> listmap2 = getDataService.getYueDuDataFromURL(Until.YUEDU_QUJI, "Y", "A");
//        getDataService.saveIndexs(listmap2, "Y", "A");
        //四个特区月度指标
//        Map<String, Object> listmap3 = getDataService.getYueDuDataFromURL(Until.YUEDU_TEQU4, "Y", "B");
//        getDataService.saveIndexs(listmap3, "Y", "B");
        //十五个副省级月度指标
//        Map<String, Object> listmap4 = getDataService.getYueDuDataFromURL(Until.YUEDU_FUSHENGJI15, "Y", "C");
//        getDataService.saveIndexs(listmap4, "Y", "C");
        //九地市月度指标
//        Map<String, Object> listmap5 = getDataService.getYueDuDataFromURL(Until.YUEDU_9DI, "Y", "E");
//        getDataService.saveIndexs(listmap5, "Y", "E");
        //全国月度指标
//        Map<String, Object> listmap6 = getDataService.getYueDuDataFromURL(Until.YUEDU_QUANGUO, "Y", "G");
//        getDataService.saveIndexs(listmap6, "Y", "G");

        //全省月度指标
        Map<String, Object> listmap7 = getDataService.getYueDuDataFromURL(Until.YUEDU_QS, "Y", "P");
        getDataService.saveIndexs(listmap7, "Y", "P");
        return coverMessage("200", "successful");
    }


    /**
     * 保存指标模板(季度)
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/getIndicatorMouldJiDu")
    public Message getIndicatorMouldJiDu() {
        /**
         * String JIDU_9DI = "app9sjd";// 	9个设区市季度数据（APP）
         * String NIANDU_9DI = "app9snd";//  9个设区市年度数据（APP）
         * String YUEDU_9DI = "app9syd";//  9个设区市月度数据（APP）
         * String JIDU_FUSHENGJI15 = "appfsjjd";//   十五个副省级季度数据（APP）
         * String NIANDU_FUSHENGJI15 = "appfsjnd";//   十五个副省级年度数据（APP）
         * String YUEDU_FUSHENGJI15 = "appfsjyd";//   十五个副省级月度数据（APP）
         * String JIDU_TEQU4 = "appjjtqjd";//    四个经济特区季度数据（APP）
         * String NIANDU_TEQU4 = "appjjtqnd";//    四个经济特区年度数据（APP）
         * String YUEDU_TEQU4 = "appjjtqyd";//    四个经济特区月度数据（APP）
         * String JIDU_QUANGUO = "appqgjd";//  全国季度数据（APP）
         * String NIANDU_QUANGUO = "appqgnd";//  全国年度数据（APP）
         * String YUEDU_QUANGUO = "appqgyd";//  全国月度数据（APP）
         * String JIDU_QUJI = "appqjjd";//  区级季度数据（APP）
         * String NIANDU_QUJI = "appqjnd";//  区级年度数据（APP）
         * String YUEDU_QUJI = "appqjyd";//  区级月度数据（APP）
         * String YEUDU_SHOUYE = "appshouye";//    首页月度数据（APP）
         * String JIDU_SHIJI = "appsjjd";//  市级季度数据（APP）
         * String NIANDU_SHIJI = "appsjnd";//  市级年度数据（APP）
         * String YUEDU_SHIJI = "appsjyd";//  市级月度数据（APP）
         */
        // A 区级 B 四个特区，C 十五个副省级 D 市级数据，E 九地市  G 全国  P 全省
        //市级季度指标
//        Map<String, Object> listmap1 = getDataService.getYueDuDataFromURL(Until.JIDU_SHIJI, "J", "D");
//        getDataService.saveIndexs(listmap1, "J", "D");
        //区级季度指标
//        Map<String, Object> listmap2 = getDataService.getYueDuDataFromURL(Until.JIDU_QUJI, "J", "A");
//        getDataService.saveIndexs(listmap2, "J", "A");
        //四个特区季度指标
//        Map<String, Object> listmap3 = getDataService.getYueDuDataFromURL(Until.JIDU_TEQU4, "J", "B");
//        getDataService.saveIndexs(listmap3, "J", "B");
        //十五个副省级季度指标
//        Map<String, Object> listmap4 = getDataService.getYueDuDataFromURL(Until.JIDU_FUSHENGJI15, "J", "C");
//        getDataService.saveIndexs(listmap4, "J", "C");
        //九地市季度指标
//        Map<String, Object> listmap5 = getDataService.getYueDuDataFromURL(Until.JIDU_9DI, "J", "E");
//        getDataService.saveIndexs(listmap5, "J", "E");
        //全国季度指标
//        Map<String, Object> listmap6 = getDataService.getYueDuDataFromURL(Until.JIDU_QUANGUO, "J", "G");
//        getDataService.saveIndexs(listmap6, "J", "G");

        //全国季度指标
//        Map<String, Object> listmap6 = getDataService.getYueDuDataFromURL(Until.JIDU_QUANGUO, "J", "G");
//        getDataService.saveIndexs(listmap6, "J", "G");

        //全省季度指标
        Map<String, Object> listmap7 = getDataService.getYueDuDataFromURL(Until.JIDU_QS, "J", "P");
        getDataService.saveIndexs(listmap7, "J", "P");
        return coverMessage("200", "successful");
    }


    /**
     * 保存指标模板(年度)
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/getIndicatorMouldNianDu")
    public Message getIndicatorMouldNianDu() {
        /**
         * String JIDU_9DI = "app9sjd";// 	9个设区市季度数据（APP）
         * String NIANDU_9DI = "app9snd";//  9个设区市年度数据（APP）
         * String YUEDU_9DI = "app9syd";//  9个设区市月度数据（APP）
         * String JIDU_FUSHENGJI15 = "appfsjjd";//   十五个副省级季度数据（APP）
         * String NIANDU_FUSHENGJI15 = "appfsjnd";//   十五个副省级年度数据（APP）
         * String YUEDU_FUSHENGJI15 = "appfsjyd";//   十五个副省级月度数据（APP）
         * String JIDU_TEQU4 = "appjjtqjd";//    四个经济特区季度数据（APP）
         * String NIANDU_TEQU4 = "appjjtqnd";//    四个经济特区年度数据（APP）
         * String YUEDU_TEQU4 = "appjjtqyd";//    四个经济特区月度数据（APP）
         * String JIDU_QUANGUO = "appqgjd";//  全国季度数据（APP）
         * String NIANDU_QUANGUO = "appqgnd";//  全国年度数据（APP）
         * String YUEDU_QUANGUO = "appqgyd";//  全国月度数据（APP）
         * String JIDU_QUJI = "appqjjd";//  区级季度数据（APP）
         * String NIANDU_QUJI = "appqjnd";//  区级年度数据（APP）
         * String YUEDU_QUJI = "appqjyd";//  区级月度数据（APP）
         * String YEUDU_SHOUYE = "appshouye";//    首页月度数据（APP）
         * String JIDU_SHIJI = "appsjjd";//  市级季度数据（APP）
         * String NIANDU_SHIJI = "appsjnd";//  市级年度数据（APP）
         * String YUEDU_SHIJI = "appsjyd";//  市级月度数据（APP）
         */
        /*// A 区级 B 四个特区，C 十五个副省级 D 市级数据，E 九地市  G 全国  P 全省
        //市级月度指标
        Map<String, Object> listmap1 = getDataService.getYueDuDataFromURL(Until.NIANDU_SHIJI, "N", "D");
        getDataService.saveIndexs(listmap1, "N", "D");
        //单独处理市级年度指标数据(5级指标)
        getDataService.getShiJiNianDuIndex(Until.NIANDU_SHIJI, "N", "D");*/


        //区级年度指标
//        Map<String, Object> listmap2 = getDataService.getYueDuDataFromURL(Until.NIANDU_QUJI, "N", "A");
//        getDataService.saveIndexs(listmap2, "N", "A");
        //四个特区年度指标
//        Map<String, Object> listmap3 = getDataService.getYueDuDataFromURL(Until.NIANDU_TEQU4, "N", "B");
//        getDataService.saveIndexs(listmap3, "N", "B");
        //十五个副省级年度指标
//        Map<String, Object> listmap4 = getDataService.getYueDuDataFromURL(Until.NIANDU_FUSHENGJI15, "N", "C");
//        getDataService.saveIndexs(listmap4, "N", "C");
        //九地市年度指标
//        Map<String, Object> listmap5 = getDataService.getYueDuDataFromURL(Until.NIANDU_9DI, "N", "E");
//        getDataService.saveIndexs(listmap5, "N", "E");
        //全国年度指标
//        Map<String, Object> listmap6 = getDataService.getYueDuDataFromURL(Until.NIANDU_QUANGUO, "N", "G");
//        getDataService.saveIndexs(listmap6, "N", "G");

        //全省年度指标
        Map<String, Object> listmap7 = getDataService.getYueDuDataFromURL(Until.NIANDU_QS, "N", "P");
        getDataService.saveIndexs(listmap7, "N", "P");
        return coverMessage("200", "successful");
    }

    /**
     * 获取地区
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/getArea")
    public Message getArea() {

        /* List<AreaCode> list  =getDataService.getArea();
         */
        // List list  = secondService.secondCatalogue("","","","");
        /**    C010104 app十五个副省级   appfsjyd
         C010105 app经济特区      appjjtqyd
         C010106 app全国         appqgyd
         C010107 app区级         appqjyd
         C010108 app市级         appsjyd
         // A 区级 B 四个特区，C 十五个副省级 D 市级数据，E 九地市  G 全国
         */
        /*List<AreaCode> list1 = getDataService.getArea("appfsjyd", "C");
        areaService.batchSave(list1);
        List<AreaCode> list2 = getDataService.getArea("appjjtqyd", "B");
        areaService.batchSave(list2);
        List<AreaCode> list3 = getDataService.getArea("appqgyd", "G");
        areaService.batchSave(list3);
        List<AreaCode> list4 = getDataService.getArea("appqjyd", "A");
        areaService.batchSave(list4);
        List<AreaCode> list5 = getDataService.getArea("appsjyd", "E");
        areaService.batchSave(list5);*/
        return coverMessage("200", "successful");
    }

}
